package com.liaowei.auth.controller;

import com.liaowei.auth.model.vo.UserVO;
import com.liaowei.auth.service.UserService;
import com.liaowei.common.BaseResponse;
import com.liaowei.common.ResultUtils;
import com.liaowei.model.param.LoginUserParam;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.Min;
import javax.validation.constraints.NotNull;
import java.util.List;

@RestController
@RequestMapping("auth")
@RequiredArgsConstructor
@Validated
public class AuthController {

    private final UserService userService;

    // 查询用户权限
    @GetMapping("permissionNames/{userId}")
    public BaseResponse<List<String>> permissionNameList(@PathVariable
                                                         @NotNull(message = "id不能为空")
                                                         @Min(value = 1, message = "id不能小于1")
                                                         Long userId) {
        return ResultUtils.success(userService.permissionNameList(userId));
    }

    // 查询用户角色
    @GetMapping("roleNames/{userId}")
    public BaseResponse<List<String>> roleNameList(@PathVariable
                                                   @NotNull(message = "id不能为空")
                                                   @Min(value = 1, message = "id不能小于1")
                                                   Long userId) {
        return ResultUtils.success(userService.roleNameList(userId));
    }

    // 用户登录认证
    @PostMapping("login")
    public BaseResponse<UserVO> login(@RequestBody @Validated LoginUserParam loginUserParam) {
        return ResultUtils.success(userService.login(loginUserParam));
    }
}
